package com.briup.corejava.day22;

import com.briup.corejava.day14.FirstAnno;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 使用反射获取注解，同时提供注解的检查
 */
public class Test3 {
    public static void main(String[] args) throws Exception{
        Class<Circle> clazz = Circle.class;
        // 以属性为例
        Field[] declaredFields = clazz.getDeclaredFields();
        List<Field> list = new ArrayList<>();
        for(Field f :declaredFields){
            // 获取每个属性上的FirstAnno注解
            FirstAnno annotation = f.getAnnotation(FirstAnno.class);
            if(annotation != null) {
                String[] type = annotation.type();
                if(type.length >= 3){
                    throw new Exception();
                }
                System.out.println(Arrays.toString(type));
            }
            Annotation[] annotations = f.getAnnotations();
            for(Annotation a : annotations){
                System.out.println(a.annotationType().getName());
            }
        }

    }
}
